﻿#region 版权信息

// ------------------------------------------------------------------------------
// Copyright: (c) 2019  梅军章
// 项目名称：Amm.UnitOfWork
// 文件名称：IUnitOfWorkOfT.cs
// 版本号: V1.0.0.0
// 创建时间：2019-07-31 9:30
// 更改时间：2019-07-31 9:46
// ------------------------------------------------------------------------------

#endregion

#region 项目引用

using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

#endregion

namespace Amm.UnitOfWork
{
    /// <summary>
    ///     Defines the interface(s) for generic unit of work.
    /// </summary>
    public interface IUnitOfWork<TContext> : IUnitOfWork where TContext : DbContext
    {
        /// <summary>
        ///     Gets the db context.
        /// </summary>
        /// <returns>The instance of type <typeparamref name="TContext" />.</returns>
        TContext DbContext { get; }

        /// <summary>
        ///     Saves all changes made in this context to the database with distributed transaction.
        /// </summary>
        /// <param name="ensureAutoHistory"><c>True</c> if save changes ensure auto record the change history.</param>
        /// <param name="unitOfWorks">An optional <see cref="IUnitOfWork" /> array.</param>
        /// <returns>
        ///     A <see cref="Task{TResult}" /> that represents the asynchronous save operation. The task result contains the
        ///     number of state entities written to database.
        /// </returns>
        Task<int> SaveChangesAsync(bool ensureAutoHistory = false, params IUnitOfWork[] unitOfWorks);
    }
}